package com.lenovo;

import com.lenovo.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author CJF
 * @version Updated at 2019/05/24 By Howie Lu
 * @date 2018/12
 * 拦截器，用于登录判断，权限拦截
 * @description 2019/5/24调整目录结构，从testreport中提取出来
 */
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    // @Resource(name = "generalInterceptor")
    @Autowired
    GeneralInterceptor interceptor;

    @Autowired
    GeneralInterceptor2 interceptor2;

    @Autowired
    GeneralInterceptor3 interceptor3;

    @Autowired
    EmailInterceptor emailInterceptor;

    @Autowired
    FeedBackInterceptor feedBackInterceptor;

    @Autowired
    JenkinsInterceptor jenkinsInterceptor;

    @Autowired
    JenkinsBuildInterceptor jenkinsBuildInterceptor;

    @Autowired
    MessageInterceptor messageInterceptor;

    @Autowired
    AllReportInterceptor allReportInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录验证拦截器1
        registry.addInterceptor(interceptor).addPathPatterns("/index", "/index.html");
        //登录验证拦截器2
        registry.addInterceptor(interceptor2).addPathPatterns("/FindAndUpdate/**", "/jenkins/**", "/Message_Record/**", "/Question/**");
        //登录验证拦截器3
        registry.addInterceptor(interceptor3).addPathPatterns("/online/**", "/qa/**", "/gray/**", "/test/**");
        //邮件功能拦截器
        registry.addInterceptor(emailInterceptor).addPathPatterns("/**/SendEmail");
        //查看反馈功能拦截器
        registry.addInterceptor(feedBackInterceptor).addPathPatterns("/**/AllQuestion", "/**/UpateQuestion", "/**/UpateQuestionBugUrl");
        //查看job功能拦截器
        registry.addInterceptor(jenkinsInterceptor).addPathPatterns("/**/job/list");
        //构建job功能拦截器
        registry.addInterceptor(jenkinsBuildInterceptor).addPathPatterns("/**/job/build", "/**/job/stop");
        //消息中心功能拦截器
        registry.addInterceptor(messageInterceptor).addPathPatterns("/Message_Record/**");
        //查看测试报告功能拦截器
        registry.addInterceptor(allReportInterceptor).addPathPatterns("/online/**", "/qa/**", "/gray/**", "/test/**");

    }
}
